/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root1
 * @param {TreeNode} root2
 * @return {TreeNode}
 */
var mergeTrees = function (root1, root2) {
    return mergeLevel(root1, root2)
};

// 确定入参和返回值，返回对应新节点
function mergeLevel(root1, root2) {
    // 确定终止条件
    if (root1 === null && root2 === null) return null
    if (root1 === null && root2 !== null) return root2
    if (root1 !== null && root2 === null) return root1

    // 确定单次递归逻辑
    let node = new TreeNode(root1.val + root2.val);
    node.left = mergeLevel(root1.left, root2.left)
    node.right = mergeLevel(root1.right, root2.right)

    return node;
}